package softtech.apps.autoanswerphonecall;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.content.Context;
import android.util.Log;

public class AppCacheData {
	
	public void SaveCache(Context context,String fileName,String data){
		String noiDung = data;
		
		try {
			FileOutputStream outPut=context.openFileOutput(fileName+".txt", Context.MODE_PRIVATE);
			byte[] epmang = noiDung.getBytes();
			outPut.write(epmang);
			Log.e("GHI FILE THANH CONG","GHI FILE "+fileName +"THANH CONG");
		} catch (Exception e) {
			Log.e("ghi file xit","loi:"+e.toString());
		}
	}
	
	public String LoadCache(Context context,String UserName){
		String cache="";
		FileInputStream inPut;
		try {

			inPut = context.openFileInput(UserName+".txt");

			BufferedReader reader = new BufferedReader(new InputStreamReader(inPut));
			try {
				String c =null;
				
				while((c=reader.readLine())!=null){
					cache+=c;
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				Log.e("loi","loi:"+e.toString());
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			Log.e("loi","loi:"+e.toString());
		}
		
		return cache;
	}
	
}
